package com.yan.watch.rxjava;

import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

import java.util.LinkedHashSet;
import java.util.Set;

@SuppressWarnings("all")
public class WeChatOfficialAccount implements ObservableOnSubscribe<String> {
    private Set<ObservableEmitter<String>> emitters;
    private String name;

    public WeChatOfficialAccount(String name) {
        this.name = name;
        emitters = new LinkedHashSet<>();
    }

    @Override
    public void subscribe(ObservableEmitter<String> e) throws Exception {
        emitters.add(e);
    }

    public void publish(String title, String content) {
        System.out.println("===========================");
        String publishContent = "公众号" + name + "发布了文章" + title + "," +
                "\n全文：\n" + content;
        emitters.forEach(e -> e.onNext(publishContent));
    }

}
